//
//  MainTabbarcontroller.m
//  weibo
//
//  Created by student on 16/4/22.
//  Copyright © 2016年 interesting. All rights reserved.
//

#import "MainTabbarcontroller.h"
#import "MeTableViewController.h"
#import "HomeTableViewController.h"
#import "MessageTableViewController.h"
#import "DiscoverTableViewController.h"
@interface MainTabbarcontroller ()

@end

@implementation MainTabbarcontroller

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tabBar.tintColor = [UIColor orangeColor];

    //1.home
    HomeTableViewController *homeVC = [[HomeTableViewController alloc]init];
    MeTableViewController *meVC = [[MeTableViewController alloc]init];
    MessageTableViewController *messageVC = [[MessageTableViewController alloc]init];
    DiscoverTableViewController *discoverVC = [[DiscoverTableViewController alloc]init];
    [self addchildcontroller:homeVC andimagename:@"tabbar_home" andtitle:@"首页" andselectedimage:@"tabbar_home_highlighted"];
    [self addchildcontroller:messageVC andimagename:@"tabbar_message_center" andtitle:@"消息" andselectedimage:@"tabbar_message_center_highlighted"];
    [self addchildcontroller:[[UIViewController alloc]init] andimagename:@"" andtitle:@"" andselectedimage:@""];
    [self addchildcontroller:discoverVC andimagename:@"tabbar_discover" andtitle:@"发现" andselectedimage:@"tabbar_discover_highlighted"];

    [self addchildcontroller:meVC andimagename:@"tabbar_profile" andtitle:@"我" andselectedimage:@"tabbar_profile_highlighted"];


}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self addcomposeBtn];    
}

- (void)addchildcontroller:(UIViewController *)vc
              andimagename:(NSString *)imagename
                  andtitle:(NSString *)title
          andselectedimage:(NSString *)selected
{
    //    HomeTableViewController *homeVC = [[HomeTableViewController alloc]init];
    vc.tabBarItem.image = [UIImage imageNamed:imagename];
    vc.tabBarItem.title = title;
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selected];
    UINavigationController *homeNavi = [[UINavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:homeNavi];
}

- (void)addcomposeBtn
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    int width = [UIScreen mainScreen].bounds.size.width/5;
    btn.frame = CGRectMake(width*2, 0, width, 49);
    [self.tabBar addSubview:btn];
    [btn addTarget:self action:@selector(composedbtnPressed) forControlEvents:UIControlEventTouchUpInside];
}

-(void)composedbtnPressed
{
    NSLog(@"OK");
}

@end
